import { MockMethod } from 'vite-plugin-mock';
import mockjs from 'mockjs';

import Pcodes from '../src/constants/premissions';

mockjs.Random.extend({
    phone: function () {
        return (
            this.pick(['130', '131', '132', '133', '135', '137', '138', '170', '187', '189']) +
            mockjs.mock(/\d{8}/)
        );
    }
});

export default [
    {
        url: '/api/login',
        method: 'post',
        response: () => {
            return mockjs.mock({
                success: true,
                code: 200,
                data: {
                    token: '@guid()'
                }
            });
        }
    },
    {
        url: '/api/logout',
        method: 'get',
        response: () =>
            mockjs.mock({
                success: true,
                code: 200
            })
    },
    {
        url: '/api/getUserInfo',
        method: 'get',
        response: () =>
            mockjs.mock({
                success: true,
                code: 200,
                data: {
                    id: '@guid()',
                    username: '@cname()',
                    avatar: '@image(200x200)',
                    phone: mockjs.Random.phone(),
                    email: '@email()',
                    'roles|1-10': ['@cword(3, 5)']
                }
            })
    },
    {
        url: '/api/getPermission',
        method: 'get',
        response: mockjs.mock({
            success: true,
            code: 200,
            data: {
                menuList: [
                    {
                        menuId: '2',
                        menuName: '示例',
                        showOrder: 1,
                        icon:'mdi/account-alert',
                        routePath: '/example'
                    },
                    {
                        menuId: '2-1',
                        menuName: '弹窗调用',
                        showOrder: 1,
                        parentId: '2',
                        icon:'mdi/account-alert',
                        routePath: '/example/openLayer',
                        src: 'Example/OpenLayer/index'
                    },
                    {
                        menuId: '2-2',
                        menuName: 'WebScoekt 封装',
                        showOrder: 2,
                        parentId: '2',
                        routePath: '/example/websocket',
                        src: 'Example/WebSocket/index'
                    },
                    {
                        menuId: '2-3',
                        menuName: '自定义表单组件',
                        showOrder: 3,
                        parentId: '2',
                        routePath: '/example/customerCmp',
                        src: 'Example/CustomerComponents/index'
                    },
                    {
                        menuId: '1',
                        menuName: '系统管理',
                        showOrder: 3,
                        icon:'mdi/account-alert',
                        routePath: '/system'
                    },
                    {
                        menuId: '1-1',
                        menuName: '用户管理',
                        showOrder: 2,
                        parentId: '1',
                        routePath: '/system/userManagement',
                        src: 'System/User/index'
                    },
                    {
                        menuId: '1-2',
                        menuName: '部门管理',
                        showOrder: 1,
                        parentId: '1',
                        routePath: '/system/departmentManagement',
                        src: 'System/Dept/index'
                    },
                    {
                        menuId: '1-3',
                        menuName: '角色管理',
                        showOrder: 3,
                        parentId: '1',
                        routePath: '/system/roleManagement',
                        src: 'System/Role/index'
                    },
                    {
                        menuId: '1-4',
                        menuName: '菜单管理',
                        showOrder: 4,
                        parentId: '1',
                        routePath: '/system/menuManagement',
                        src: 'System/Menu/index'
                    },
                    {
                        menuId: '1-5',
                        menuName: '权限字管理',
                        showOrder: 5,
                        parentId: '1',
                        routePath: '/system/premCodeManagement',
                        src: 'System/PremCode/index'
                    },
                    {
                        menuId: '1-6',
                        menuName: '权限管理',
                        showOrder: 6,
                        parentId: '1',
                        routePath: '/system/premManagement',
                        src: 'System/Prem/index'
                    },
                    {
                        menuId: '1-7',
                        menuName: '字典管理',
                        showOrder: 7,
                        parentId: '1',
                        routePath: '/system/docManagement',
                        src: 'System/Doc/index'
                    },
                    {
                        menuId: '3',
                        menuName: '用户中心',
                        showOrder: 1,
                        icon:'mdi/account-alert',
                        routePath: '/profile',
                        isHidden: true,
                        src: 'Base/User/index'
                    }
                ],
                permissionCodes: [
                    Pcodes.formSysDataPre_fragmentSysDataPre,
                    Pcodes.formSysDataPre_fragmentSysDataPreUser,
                    Pcodes.formSysDataPre_fragmentSysDataPreUser_add,
                    Pcodes.formSysDataPre_fragmentSysDataPreUser_delete
                ]
            }
        })
    }
] as MockMethod[];
